package com.huang.factory;

import org.junit.Test;

/**
 * <p>计算器运算朱磊</p>
 *
 * @author aneng huang
 * @since 2020-10-27 10:50:24
 */
public class CalculatorMain {

    /**
     * 对象编程
     */
    @Test
    public void operatorOne() {
        double a = OperatorOne.getResult("+", 10, 10);
        System.out.println(a);
        a = OperatorOne.getResult("/", 10, 20);
        System.out.println(a);
        a = OperatorOne.getResult("-", 10, 10);
        System.out.println(a);
        a = OperatorOne.getResult("*", 10, 10);
        System.out.println(a);
    }

    /**
     * 实现的方式
     */
    @Test
    public void operatorTwoTest() {
        Calculator calculator = new Calculator(100, 200);
        double result = new OperatorAdd().getResult(calculator);
        System.out.println("加法" + result);
        result = new OperatorSub().getResult(calculator);
        System.out.println("减法" + result);
        result = new OperatorMul().getResult(calculator);
        System.out.println("乘法" + result);
        result = new OperatorDiv().getResult(calculator);
        System.out.println("除法" + result);
    }

    /**
     * 工厂类模式实现
     */
    @Test
    public void factoryModel() {
        Calculator calculator = new Calculator(100, 200);
        double result = CalculatorFactory.createOperator("+").getResult(calculator);
        System.out.println("加法" + result);
        result = CalculatorFactory.createOperator("-").getResult(calculator);
        System.out.println("减法" + result);
        result = CalculatorFactory.createOperator("*").getResult(calculator);
        System.out.println("乘法" + result);
        result = CalculatorFactory.createOperator("/").getResult(calculator);
        System.out.println("除法" + result);
    }
}
